package edu.harding.redzone;

import java.util.ArrayList;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.RectF;

public class Player
{
	private ArrayList<Point> mPoints = new ArrayList<Point>();

	private int mX = 0;
	private int mY = 0;

	private int mTop = 0;
	private int mBottom = 0;
	private int mLeft = 0;
	private int mRight = 0;

	private int mStartX;
	private int mStartY;
	private int mStopX;
	private int mStopY;

	private int mId;

	private Path mPath = new Path();

	private String mType;

	private float[] mLine;

	private boolean mSelected;

	private RectF mRectF = new RectF();

	private PathRoute mPathRoute;

	private final int CLEAR = 4;

	public Player(Resources res)
	{
		mPathRoute = new PathRoute(this.Id());
	}

	public void doDraw(Canvas canvas, Paint paint, Bitmap bitmap)
	{
		canvas.drawBitmap(bitmap, mX, mY, paint);
		if (OffenseModeActivity.Mode() == CLEAR
				|| DefenseModeActivity.Mode() == CLEAR)
		{
			this.PathRoute().Path().reset();
			this.ResetLine();
			this.Oval().setEmpty();
		}
		else
		{
			canvas.drawPath(this.PathRoute().Path(), paint);
			canvas.drawLines(this.Line(), paint);
			canvas.drawOval(this.Oval(), paint);
		}
	}
	
	public void Type(String type)
	{
		mType = type;
	}

	public String Type()
	{
		return mType;
	}

	public Path Path()
	{
		return mPath;
	}

	public void PathPoints(ArrayList<Point> value)
	{
		mPoints.clear();
		mPoints = value;
	}

	public ArrayList<Point> PathPoints()
	{
		return mPoints;
	}

	public PathRoute PathRoute()
	{
		return mPathRoute;
	}

	public void Id(int value)
	{
		mId = value;
	}

	public int Id()
	{
		return mId;
	}

	public void Line(int x, int y)
	{
		mStartX = x - 10;
		mStartY = y;
		mStopX = x + 10;
		mStopY = y;
	}

	public void ResetLine()
	{
		mStartX = 0;
		mStopX = 0;
		mStartY = 0;
		mStopY = 0;
	}

	public float[] Line()
	{
		mLine = new float[] { mStartX, mStartY, mStopX, mStopY };

		return mLine;
	}

	public void Oval(int x, int y)
	{
		zoneOrientation(x, y);

		mRectF.set(mLeft, mTop, mRight, mBottom);
	}

	public RectF Oval()
	{
		return mRectF;
	}

	public boolean IsSelected()
	{
		return mSelected;
	}

	public void IsSelected(boolean value)
	{
		mSelected = value;
	}

	public int Top()
	{
		return mTop;
	}

	public void Top(int value)
	{
		mTop = value;
	}

	public int Bottom()
	{
		return mBottom;
	}

	public void Bottom(int value)
	{
		mBottom = value;
	}

	public int Left()
	{
		return mLeft;
	}

	public void Left(int value)
	{
		mLeft = value;
	}

	public void Right(int value)
	{
		mRight = value;
	}

	public int Right()
	{
		return mRight;
	}

	public int StartX()
	{
		return mStartX;
	}

	public void StartX(int value)
	{
		mStartX = value;
	}

	public int StartY()
	{
		return mStartY;
	}

	public void StartY(int value)
	{
		mStartY = value;
	}

	public int StopX()
	{
		return mStopX;
	}

	public void StopX(int value)
	{
		mStopX = value;
	}

	public int StopY()
	{
		return mStopY;
	}

	public void StopY(int value)
	{
		mStopY = value;
	}

	public int X()
	{
		return mX;
	}

	public void X(int value)
	{
		mX = value;
	}

	public int Y()
	{
		return mY;
	}

	public void Y(int value)
	{
		mY = value;
	}

	public String toString()
	{
		return "Coordinates: (" + mX + "," + mY + ")";
	}

	private void zoneOrientation(int x, int y)
	{
		if (y < Y())
		{
			mLeft = x - 90;
			mTop = y - 60;
			mRight = x + 90;
			mBottom = y;
		} else if (y > Y())
		{
			mLeft = x - 90;
			mTop = y;
			mRight = x + 90;
			mBottom = y + 60;
		}
	}
}
